package com.zoro.dyformservice.business.user.entity;

import com.zoro.dyformservice.business.blog.entity.UserBlog;
import com.zoro.dyformservice.business.role.entity.RoleInfo;
import com.zoro.dyformservice.constants.response.common.YesOrNo;
import com.zoro.dyformservice.support.jpa.converters.YesOrNoConverter;
import jakarta.persistence.*;
import org.hibernate.annotations.LazyGroup;

import java.util.Date;
import java.util.List;

/**
 * @author zhaoxingwu
 */
@Entity
@Table(name = "df_user_info")
public class UserInfoEntity {

    @Id
    @Column(name = "user_id")
    private String userId;
    @Column(name = "account")
    private String account;
    @Column(name = "password")
    private String password;
    @Column(name = "user_name")
    @LazyGroup("user_name")
    private String userName;
    @Column(name = "locked")
    @Convert(converter = YesOrNoConverter.class)
    private YesOrNo locked;
    @Convert(converter = YesOrNoConverter.class)
    @Column(name = "deleted")
    private YesOrNo deleted;
    @Column(name = "create_time")
    private Date createTime;
    // lazy 不会生效
    @OneToOne(mappedBy = "userInfo", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private UserInfoExtEntity userInfoExt;

    @OneToMany(mappedBy = "userInfo", fetch = FetchType.LAZY)
    private List<UserBlog> blogs;

    @ManyToMany(mappedBy = "users")
    private List<RoleInfo> roleInfos;

    public List<RoleInfo> getRoleInfos() {
        return roleInfos;
    }

    public void setRoleInfos(List<RoleInfo> roleInfos) {
        this.roleInfos = roleInfos;
    }

    public List<UserBlog> getBlogs() {
        return blogs;
    }

    public void setBlogs(List<UserBlog> blogs) {
        this.blogs = blogs;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public UserInfoExtEntity getUserInfoExt() {
        return userInfoExt;
    }

    public void setUserInfoExt(UserInfoExtEntity userInfoExt) {
        this.userInfoExt = userInfoExt;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public YesOrNo getLocked() {
        return locked;
    }

    public void setLocked(YesOrNo locked) {
        this.locked = locked;
    }

    public YesOrNo getDeleted() {
        return deleted;
    }

    public void setDeleted(YesOrNo deleted) {
        this.deleted = deleted;
    }

    @Override
    public String toString() {
        return "UserInfoEntity{" +
                "userId='" + userId + '\'' +
                ", account='" + account + '\'' +
                ", password='" + password + '\'' +
                ", userName='" + userName + '\'' +
                ", locked=" + locked +
                ", deleted=" + deleted +
                ", createTime=" + createTime +
                '}';
    }
}
